<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style>
        .box{
            margin-top:20px;
            margin-bottom:10px;
        }
        .required_text{
            color:red;
            padding: 8px;
        }
    </style>
</head>
<body>

<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <!--资源-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2>5、商品信息配置</h2>
                </div>
                <div class="layui-card-body">
                    <div class="box">
                        <div>
                            <form class="layui-form" id="source">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">商品</label>
                                    <div class="layui-input-inline" style="width: 800px">
                                        <select id="addGoods" name="goods_id" lay-filter="addGoods" lay-search>
                                            <option value="">请填写商品名称</option>
                                            {if !empty($info.goods_id)}
                                            <option value="{$goodsData.goods_id}" selected="selected">{$goodsData.goods_name}</option>
                                            {/if}
                                        </select>
                                    </div>
                                    <button class="layui-btn layui-btn-danger layui-btn-radius" lay-submit lay-filter="source">保存</button>
                                </div>

                                <!--<div class="layui-form-item" id="carPriceConfig" {empty name='$goodsData'}style="display: none;"{/empty}>-->
                                    <!--<label class="layui-form-label">派单价配置</label>-->
                                    <!--<div class="layui-input-inline" style="width: 800px">-->
                                        <!--&lt;!&ndash;<a href="{:url('admin/goods/addclassify')}" class="layui-btn layui-btn-warm addclassify"  style="margin-right: 0;margin-top:2px;font-size:12px;background: #51a954">商品套餐</a>&ndash;&gt;-->
                                        <!--&lt;!&ndash;<a href="{:url('admin/goods/setgoodsprice')}" class="layui-btn layui-btn-warm setgoodsprice"  style="margin-right: 0;margin-top:2px;font-size:12px;background: darkslategrey">商品价格</a>&ndash;&gt;-->
                                        <!--<a href="{:url('admin/goods/setgoodscartype')}" class="layui-btn layui-btn-warm setgoodscartype"  style="margin-right: 0;margin-top:2px;font-size:12px;background: #1e9fff">套餐车型</a>-->
                                    <!--</div>-->
                                <!--</div>-->


                                <input type="hidden" id="page_index" name="page_index" value="0">
                                <input type="hidden" class="standard_id" name="id" {notempty name='$info'}value="{$info.id}"{/notempty}>

                                <div class="layui-form-item" style="margin-top:50px;">
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-radius" id="source_prev">上一页</button>
                                        <button class="layui-btn layui-btn-radius" id="finish_btn">完成</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    layui.use(['element','layer', 'form'], function() {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        $('.addclassify').click(function(){
            var goods_id = $("#addGoods").val();
            if(goods_id==''){
                layer.msg("请选择商品");
                return false;
            }
            var url = $(this).attr('href');
            url = url+"?id="+goods_id;
            layer.open({
                type:2,
                content:url,
                area: ['95%', '95%'],
                end:function(){
                    location.reload();
                }
            });
            return false;
        });

        $('.setgoodsprice').click(function(){
            var goods_id = $("#addGoods").val();
            var standard_id = "{$info.id}";
            if(goods_id==''){
                layer.msg("请选择商品");
                return false;
            }
            var url = $(this).attr('href');
            url = url+"?id="+goods_id+"&standard_id="+standard_id;
            layer.open({
                type:2,
                content:url,
                area: ['95%', '95%'],
                end:function(){
                    location.reload();
                }
            });
            return false;
        });

        $('.setgoodscartype').click(function(){
            var goods_id = $("#addGoods").val();
            if(goods_id==''){
                layer.msg("请选择商品");
                return false;
            }
            var url = $(this).attr('href');
            url = url+"?id="+goods_id;
            layer.open({
                type:2,
                content:url,
                area: ['95%', '95%'],
                end:function(){
                    //location.reload();
                }
            });
            return false;
        });

        //***************************************************************************
        //资源信息提交
        form.on('submit(source)', function() {
            var goods_id = $("#addGoods").val();
            if(goods_id==''){
                layer.msg("请选择商品");
                form.render("select");
                return false;
            }

            $.ajax({
                url:"{:url('admin/standard/submitSourceData')}",
                data:$('#source').serialize(),
                type:'post',
                async: false,
                success:function(res) {
                    $("#goods_id").attr("value",goods_id);
                    layer.msg(res.msg);
                    //显示配置车型
                    $("#carPriceConfig").show();
                    return false;
                }
            });
            return false;
        });

        //上一页   行程分段配置价格页
        $("#source_prev").click(function(){
            location.href = "{:url('admin/product/setsection',['id'=>$info.id])}";
            return false;
        });

        //完成  下一页
        $("#finish_btn").click(function(){
            var goods_id = $("#addGoods").val();
            if(goods_id==''){
                layer.msg("请选择商品");
                return false;
            }

            var page_index = $("#page_index").val();
            var id = $(".standard_id").val();
            $.ajax({
                url:"{:url('admin/standard/submitPageIndex')}",
                data:{id:id,page_index:page_index},
                type:'post',
                async: false,
                success:function(res) {
                    layer.msg(res.msg);
                    setTimeout(function(){
                        location.href = "{:url('admin/standard/detail',['id'=>$info['id']])}";
                    },1500);
                }
            });

            return false;
        });


        //模糊查询商品list
        var cpLock1 = true;
        function bindFunc1(){
            //解决监听输入时中文输入法问题
            $("#addGoods").parent().find(".layui-select-title input").on('compositionstart', function () {
                cpLock1 = false;
            });
            $("#addGoods").parent().find(".layui-select-title input").on('compositionend', function () {
                cpLock1 = true;
            });
            $("#addGoods").parent().find(".layui-select-title input").bind('input propertychange',function(){
                var GoodsName = $(this).val();
                showGoodsList(GoodsName);
            });
            //点击时选中文本
            $("#addGoods").parent().find(".layui-select-title input").attr("onfocus","this.select()");
        }
        bindFunc1();
        function showGoodsList(GoodsName){
            setTimeout(function(){
                if (cpLock1) {
                    var html="<option value=''>请填写商品名称</option>";
                    $.ajax({
                        url:"{:url('admin/standard/showGoodsList')}",
                        data:{'GoodsName':GoodsName},
                        type:'post',
                        async: false,
                        success:function(data) {
                            for(var i=0;i<data.length;i++){
                                html += "<option value="+data[i]["goods_id"]+">"+data[i]["goods_id"]+"__"+data[i]["goods_tcode"]+"__"+data[i]["goods_name"]+"</option>";
                            }
                            $("#addGoods").html(html);
                        }
                    });

                    //重新渲染select
                    form.render('select');
                    bindFunc1();

                    $("#addGoods").next().addClass("layui-form-selected");
                    $("#addGoods").next().find(".layui-input").focus();
                    $("#addGoods").next().find(".layui-input").val(GoodsName);
                }
            },1);
        }


    });

</script>

</body>
</html>
